using Godot;
using System;

public partial class BehaviorTree : Node
{
	public BTNode root_node;
	public Characters _character;
	public override void _Ready()
	{
        if(GetChildCount() == 0)
        {return;}
		root_node = GetChild<BTNode>(0);
		root_node.completed += On_root_completed;
		
		root_node.run();
        _character = Owner as Characters;
	}

	public void On_root_completed(bool result)
	{
		root_node.run();
	}

	private Characters FindParentOfType<T>(Node node) where T : Node  //获取控制父节点，角色
    {  
        Node parent = node.GetParent<Node>();  
        while (parent != null)  
        {  
            if (parent is Characters typedParent)  
            {  
                // 找到了特定类型的父节点  
                return typedParent;  
            }  
            // 继续向上遍历父节点  
            parent = parent.GetParent<Node>();  
        }  
        // 没有找到特定类型的父节点  
        return null;  
    }  
}
